// import axios from 'axios'
import {
  observable,
  toJS,
  action,
} from 'mobx'

export default class AppStore {
  @observable user = {
    isLogin: false,
    info: {},
  }

  init({ user }) {
    if (user) {
      this.user = user
    }
  }

  @action login(userInfo) {
    return new Promise((resolve, reject) => {
      this.user.info = {
        username: userInfo.username,
      }
      this.user.isLogin = true
      resolve()
    })
  }

  @action getUserDetail() {

  }

  @action logout() {
    return new Promise((resolve, reject) => {
      this.user.info = {}
      this.user.isLogin = false
      resolve()
    })
  }

  toJson() {
    return {
      user: toJS(this.user),
    }
  }
}
